﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReAnimation.MVP.ViewInterfaces;
using ReAnimation.MVP.Models.Interfaces;

namespace ReAnimation.MVP.Presenters
{
    public class SceneManipulationPresenter: BasePresenter<ISceneManipulationView>
    {
        IMainModel _mainModel;

        public SceneManipulationPresenter(IMainModel mainModel)
        {
            _mainModel = mainModel;

            _mainModel.MoleculesCollectionChanged += new EventHandler(_mainModel_MoleculesCollectionChanged);
        }

        void _mainModel_MoleculesCollectionChanged(object sender, EventArgs e)
        {
            UpdateViewControls();
        }

        protected override void InitView()
        {
            UpdateViewControls();
        }

        private void UpdateViewControls()
        {

            View.CameraNavigationEnabled = AnyMolecule();
            
        }

        private bool AnyMolecule()
        {
            return _mainModel.CurrentAnimation != null &&
                           _mainModel.CurrentAnimation.AnimationSteps != null &&
                           _mainModel.CurrentAnimation.AnimationSteps.Any() &&
                           _mainModel.CurrentAnimation.AnimationSteps.First().Molecules != null &&
                           _mainModel.CurrentAnimation.AnimationSteps.First().Molecules.Any();
        }
    }
}
